﻿@{
    ViewBag.Title = "OA办公系统";
    Page.BodyStyle = "class='mainBody'";
}
<style type="text/css">
    html,body {overflow:hidden; }
</style>
<script src="~/Scripts/jquery.signalR-1.2.2.min.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
    $(window).load(function ()
    {
        //var proxy = $.connection.signalRHub;
        //proxy.client.receiveMessage = function (message)
        //{
        //    alert(message);
        //};
        //$.connection.hub.start();

        var connection = $.connection('@Url.Content("~/yunjian")');
        connection.start().done(function () { });
        connection.received(function (data)
        {
            showMessage(data);
        });
    });
    function showMessage(data)
    {
        var json = JSON.parse(data);
        var id = json.id || "";
        if (json.title && json.title.length > 0)
        {
            $("#messagetitle").text(json.title);
        }
        var html = '<div class="msg">' + json.contents + '</div>';
        if (json.count && json.count > 1)
        {
            html += '<div style="margin-top:6px;"><a class="blue1" href="javascript:void(0);" onclick="openApp(\'/ShortMessage/NoRead\',0,\'未读消息\',\'noreadmessage\');closeMessage(\'' + id + '\');return false;">您还有' + json.count + '条未读消息，点击查看。</a></div>';
        }
        $("#messagecontent").html(html);
        $("#message").hide().slideDown(800);
    }
    function closeMessage(id)
    { 
        $("#message").hide(400);
        if (id && id.length > 0)
        {
            $.ajax({ url: RoadUI.Core.rooturl() + "/ShortMessage/UpdateStatus?id=" + id });
        }
    }
</script>
<div class="homemsgdiv" id="message">
    <div class="homemsgdivtitlediv">
        <div class="homemsgdivtitlediv1"></div>
        <div class="homemsgdivtitlediv1bg">
            <div class="homemsgdivtitlediv1bgtitle" id="messagetitle"></div>
            <div class="homemsgdivtitlediv1bgclose" onclick="closeMessage();return false;"></div>
        </div>
    </div>
    <div class="homemsgdivmsg" id="messagecontent">
    </div>
</div>
<div class="mainTop">
    <div class="mainTopLeft"></div>
    <div class="mainTopRight">
        <div style="padding-right:10px; padding-top:9px;">
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td rowspan="2" valign="middle" style="vertical-align:middle; padding-right:10px;">
                        <img src="@ViewBag.HeadImg" width="38" height="38" id="UserHeadImg" style="vertical-align:middle;border-radius:38px" runat="server" />
                    </td>
                    <td style="text-align:left;">
                        <div>
                            <span>欢迎您：@ViewBag.UserName</span>
                            <span style="margin-right:6px;"></span>
                            <span style="margin-right:6px;">今天是：<span id="CurrentDateTimeSpan">@ViewBag.DateTime</span></span>
                            <span style="">主题：</span>
                            <span class="mainTheme_blue" onclick="changeTheme('Blue', true);"></span>
                            <span class="mainTheme_green" onclick="changeTheme('Green', true);"></span>
                            <span class="mainTheme_gray" onclick="changeTheme('Gray', true);"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:left;">
                        <div style="margin-top:6px;">
                            @*<span style="margin-right:4px;"><a href="http://www.cqroad.cn" class="white" target="_blank">官方网站</a></span>
                            <span style="margin-right:6px;">|</span>*@
                            <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('Home/Home',0,'个人空间','index'); return false;" class="white" >个人空间</a></span>
                            <span style="margin-right:6px;">|</span>
                            <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('/Members/EditPass',2,'修改密码','index_editpass',500,210); return false;" class="white" >修改密码</a></span>
                            <span style="margin-right:6px;">|</span>
                            <span style="margin-right:4px;"><a href="javascript:void(0);" onclick="if(confirm('您真的要退出登录吗?')){window.location='@Url.Content("~/Login/Quit")';} return false;" class="white">退出登录</a></span>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        
    </div>
    <div style="clear:both;"></div>
</div>
<div class="mainDiv">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
    <tr>
        <td class="mainMenutd" id="mainMenutd" style="display:none;">
            <table cellpadding="0" cellspacing="0" width="100%" border="0">
                <tr>
                    <td class="menutd">
                        <div class="menuDiv">
                            <div class="menuDivRightTitle">
                                <div style="float:left; padding-left:3px;"><i class="fa fa-desktop" style="font-size:14px; margin-right:4px;"></i>管理菜单</div>
                                <div class="menuswitchleft" onclick="switchMenu(this,0);"><i class="fa fa-angle-double-left"></i></div>
                            </div>
                        </div>
                    </td>
                    <td valign="top" style="vertical-align:top;">
                        <div class="mainSplittdImg">
                            
                        </div>
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2" class="menutd1" style="vertical-align:top;">
                        <div class="menuDivRight" style="clear:both;">
                            <div style="overflow:hidden;">
                                <div id="treeDiv" style="margin:0;width:195px;overflow:auto; overflow-x:hidden;">
                                    @Html.Raw(new YJ.Platform.Menu().GetUserMenu(YJ.Platform.Users.CurrentUserID))
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        </td>
        <td style="width:60px; display:none;" id="mainMenutd1" style="vertical-align:top;" >
            <table cellpadding="0" cellspacing="0" width="100%" border="0">
                <tr>
                    <td class="menutd" style="width:40px;">
                        <div class="menuDiv">
                            <div class="menuDivRightTitle">
                               <div class="menuswitchright" onclick="switchMenu(this,1);"><i class="fa fa-angle-double-right"></i></div>
                            </div>
                        </div>
                    </td>
                    <td valign="top">
                        <div class="mainSplittdImg">
                            
                        </div>
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2" class="menutd1" style="vertical-align:top;">
                        <div class="menuDivRight" style="clear:both;width:60px;">
                            <div style="overflow:hidden;">
                                <div id="treeDiv1" style="margin:0;overflow:auto; overflow-x:hidden;">
                                   @Html.Raw(new YJ.Platform.Menu().GetUserMenu1(YJ.Platform.Users.CurrentUserID))
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        </td>
        <td style="vertical-align:top;" valign="top">
            <div class="tab_top"></div>
            <div id="mainTabDiv" class="mainTabDiv"></div>
        </td>
    </tr>
</table>
</div>

<script type="text/javascript">
    var mainTab = null;
    var mainTree = null;
    var mainDialog = new RoadUI.Window();
    var currentDateTimeSpan = $("#CurrentDateTimeSpan");
    var userID = '@YJ.Platform.Users.CurrentUserID';
    var rootdir = '@WebMvc.Common.Tools.BaseUrl';
    var currentWindow = null;//当前操作窗口对象
    var lastURL = "";//最后操作的页面地址
    var scrollParams = { cursorcolor: "#ACACAC", autohidemode: "leave", horizrailenabled: false };
    $(function ()
    {
        $.cookies.set("rootdir", rootdir, { expiresAt: new Date(2099, 1, 1) });
        //从cookie读取用户上次的菜单类型并设置
        var usermenutype = $.cookies.get("usermenutype");
        if ("1" == usermenutype)
        {
            switchMenu($(".menuswitchright"), 1);
        }
        else if ("0" == usermenutype)
        {
            switchMenu($(".menuswitchleft"), 0);
        }
        else
        {
            if ($(window).width() < 1024)//屏幕宽度小于1024显示窄菜单模式
            {
                switchMenu($(".menuswitchright"), 0);
            }
            else
            {
                switchMenu($(".menuswitchright"), 1);
            }
        }
        //菜单类型设置完成
        var windowheight = $(window).height() - 64;
        $('#mainTabDiv').height(windowheight - 3);
        $('.menuDivLeft').height(windowheight);
        $('.menuDivRight').height(windowheight);
        $('.menuDivRight>div>div').height(windowheight - 38);

        $(window).bind('resize', function ()
        {
            var height = $(window).height() - 64;
            $('#mainTabDiv').height(height - 3);
            $('.menuDivLeft').height(height);
            $('.menuDivRight').height(height);
            $('.menuDivRight>div>div').height(height - 38);
            mainTab.topResize(height);
            $("#treeDiv").getNiceScroll().resize(scrollParams);
        });

        mainTab = new RoadUI.Tab({ id: "mainTabDiv", replace: true });
        //initMenu();
        openApp(rootdir + "/Home/Home", 0, "个人空间", "index");

        //初始化主题按钮样式
        var theme = $.cookies.get("theme_platform") || "Blue";
        changeTheme(theme, false);

        //初始显示未读消息
        try
        {
            var noReadMsgJson = JSON.stringify(@Html.Raw(ViewBag.NoReadMsgJson));
            if (noReadMsgJson && noReadMsgJson.length>0)
            {
                showMessage(noReadMsgJson);
            }
        }
        catch (e) { }

        var nice = $("#treeDiv").niceScroll(scrollParams);
        var nice1 = $("#treeDiv1").niceScroll(scrollParams);
    });

    //宽菜单点击事件
    function menuClick(div, isref1)
    {
        var $div = $(div);
        var id = $div.attr("data-id");
        var title = $div.attr("data-title");
        var url = $div.attr("data-url");
        var model = $div.attr("data-model");
        var width = $div.attr("data-width");
        var height = $div.attr("data-height");
        var childs = $div.attr("data-childs");
        
        if (0 == isref1)
        {
            $("#treeDiv .menulistdivhover").removeClass().addClass("menulistdiv");
        }
        else
        {
            $(".menulistdivhover").removeClass().addClass("menulistdiv");
        }
        $div.removeClass().addClass("menulistdivhover");
        if ("1" == childs)
        {
            addChildMenu(id, $div, isref1);
        }
        else if (1 == isref1)
        {
            $(".menulistdiv11sub").hide();//小菜单时点击后隐藏菜单
        }
        if ($.trim(url.length) > 0)
        {
            openApp(url, model, title, id, parseInt(width), parseInt(height), true);
        }
    }

    //小菜单点击事件
    function menuClick1(div)
    {
        var $div = $(div);
        var id = $div.attr("data-id");
        var title = $div.attr("data-title");
        var url = $div.attr("data-url");
        var model = $div.attr("data-model");
        var width = $div.attr("data-width");
        var height = $div.attr("data-height");
        var childs = $div.attr("data-childs");
        $(".menulistdiv11hover").removeClass().addClass("menulistdiv11");
        $div.removeClass().addClass("menulistdiv11hover");
        if ("1" == childs)
        {
            addChildMenu1(id, $div);
        }
        else
        {
            $(".menulistdiv11sub").hide();
        }

        if ($.trim(url.length) > 0)
        {
            openApp(url, model, title, id, parseInt(width), parseInt(height), true);
        }
    }

    var parentCount = 0;
    var childMenuDivs = [];
    var isLoadMenu = true;//防止重复加载
    //isref1 1为小菜单 0为大菜单
    function addChildMenu(id, $div, isref1)
    {
        var $childs = 1 == isref1 ? $("[data-parent='" + id + "'][data-isrefresh1='1']") : $("#treeDiv [data-parent='" + id + "']");
        var $loadDiv = $(".menulistdiv2 i", $div);
        if ($childs.size() == 0 && isLoadMenu)
        {
            //$loadDiv.removeClass().addClass("fa fa-spinner");
            isLoadMenu = false;
            parentCount = 0;
            getParentCount($div.attr("data-parent"), isref1);
            parentCount++;
            var paddingLeft = parentCount * 11;
            $.ajax({
                url: rootdir + "/Home/MenuRefresh1?refreshid=" + id + "&isrefresh1=" + (1 == isref1 ? "1" : "0"), async: false, success: function (html)
                {
                    if (html.indexOf('loginstatus') >= 0 && -1 == JSON.parse(html).loginstatus)
                    {
                        login();
                    }
                    var $html = $(html);
                    $(".menulistdiv1", $html).css("padding-left", paddingLeft.toString() + "px");
                    $div.after($html);
                    $loadDiv.removeClass().addClass("fa fa-angle-down");
                    isLoadMenu = true;
                }
            });
        }
        else
        {
            var cls = $loadDiv.attr("class");
            var isClose = true;
            if ("fa fa-angle-down" == cls)
            {
                $loadDiv.removeClass().addClass("fa fa-angle-left");
            }
            else
            {
                $loadDiv.removeClass().addClass("fa fa-angle-down");
                isClose = false;
            }
            childMenuDivs = new Array();
            for (var i = 0; i < $childs.size() ; i++)
            {
                if (isClose)
                {
                    $childs.eq(i).hide();
                }
                else
                {
                    $childs.eq(i).show();
                }
                addAllChilds($childs.eq(i).attr("data-id"), isref1);
            }
            for (var i = 0; i < childMenuDivs.length; i++)
            {
                if (isClose)
                {
                    childMenuDivs[i].attr("data-show", childMenuDivs[i].is(':visible') ? "1" : "0");
                    childMenuDivs[i].hide();
                }
                else
                {
                    if ("1" == childMenuDivs[i].attr("data-show"))
                    {
                        childMenuDivs[i].show();
                    }
                }
            }
        }
        $("#treeDiv").getNiceScroll().resize(scrollParams);
    }

    function addChildMenu1(id, $div)
    {
        
        $(".menulistdiv11sub").hide();
        var $childs = $(".menulistdiv11sub[data-parent='" + id + "']");
        if ($childs.size() == 0 && isLoadMenu)
        {
            isLoadMenu = false;
            parentCount = 0;
            getParentCount($div.attr("data-parent"), 1);
            parentCount++;
            var paddingLeft = parentCount * 11;
            $.ajax({
                url: rootdir + "/Home/MenuRefresh1?refreshid=" + id + "&isrefresh1=1", async: true, success: function (html)
                {
                    if (html.indexOf('loginstatus') >= 0 && -1 == JSON.parse(html).loginstatus)
                    {
                        login();
                    }
                    var $html = $(html);
                    var $menuDiv = $('<div class="menulistdiv11sub" data-parent="' + id + '"></div>');
                    var left = $div.position().left + 55;
                    var top = $div.position().top - 1;
                    $menuDiv.append($html);
                    $(document.body).append($menuDiv);
                    if (($menuDiv.height() + top) > $("#treeDiv1").height())
                    {
                        top = top - $menuDiv.height() + $div.height();
                    }
                    $menuDiv.css("left", left);
                    $menuDiv.css("top", top);
                    $menuDiv.niceScroll(scrollParams);
                    isLoadMenu = true;
                }
            });
        }
        else
        {
            $childs.show();
        }
    }

    function addAllChilds(id, isref1)
    {
        var $divs = 1 == isref1 ? $("[data-parent='" + id + "'][data-isrefresh1='1']") : $("#treeDiv [data-parent='" + id + "']");
        if ($divs.size() > 0)
        {
            for (var i = 0; i < $divs.size() ; i++)
            {
                childMenuDivs.push($divs.eq(i));
                addAllChilds($divs.eq(i).attr("data-id"));
            }
        }
    }

    function getParentCount(parentId, isref1)
    {
        var $divs = 1 == isref1 ? $("[data-id='" + parentId + "'][data-isrefresh1='1']") : $("#treeDiv [data-id='" + parentId + "']");
        if ($divs.size() > 0)
        {
            parentCount++;
            var pid = $divs.first().attr("data-parent");
            if (pid && pid.length > 0)
            {
                getParentCount(pid);
            }
        }
    }

    function treeClick(json)
    {
        if (json)
        {
            openApp(json.link, json.model, json.title, json.id, parseInt(json.width), parseInt(json.height), true);
        }
    }

    function openApp(url, model, title, id, width, height, isAppendParams)
    {
        if (!url || url.toString().length == 0)
        {
            return;
        }
        if (!id)
        {
            id = RoadUI.Core.query("tabid", url);
            if (id)
            {
                id = id.replace("tab_", "");
            }
        }
        if (!id)
        {
            id = RoadUI.Core.newid();
        }
        if (width == 0) width = undefined;
        if (height == 0) height = undefined;
        if (isAppendParams)
        {
            url += url.indexOf('?') >= 0 ? "&appid=" + id : "?appid=" + id;
        }
        title = RoadUI.Core.decodeUri(title);
        url = $.trim(url).substr(0, 1) == "/" ? rootdir + url : url;
        switch (parseInt(model))
        {
            case 0:
                mainTab.addTab({ id: "tab_" + id.replaceAll('-', ''), title: title, src: url });
                break;
            case 1:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: false });
                break;
            case 2:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: true });
                break;
            case 3:
                RoadUI.Core.open(url + "&isopenwindow=1", width || 800, height || 460, title);
                break;
            case 4:
                window.showModalDialog(url + "&isopenwindow=1", null, "dialogWidth=" + (width || 800) + "px;dialogHeight=" + (height || 460) + "px;center=1");
                break;
            case 5:
                window.open(url + "&isopenwindow=1");
                break;
        }
    }

    function switchMenu(div, t)
    {
        var $div = $(div).parent().parent().parent();
        if (0 == t)
        {
            $("#mainMenutd1").show(200);
            $("#mainMenutd").hide();
        }
        else if (1 == t)
        {
            $("#mainMenutd").show(200);
            $("#mainMenutd1").hide();
        }
        $.cookies.set("usermenutype", t, { expiresAt: new Date(2099, 1, 1) });
        $(".menulistdiv11sub").remove();
    }

    function initMenu()
    {
        mainTree = new RoadUI.Tree({
            id: "treeDiv", path: rootdir + "/Home/Menu",
            refreshpath: rootdir + "/Home/MenuRefresh",
            showroot: false, showline: true, onclick: treeClick
        });
    }

    function changeTheme(themeName, isCng)
    {
        if (!themeName || themeName.toString().trim().length == 0)
        {
            themeName = $.cookies.get("theme_platform")
        }

        $("span[class^='mainTheme_']").each(function ()
        {
            var cssName = $(this).attr("class");
            $(this).removeClass().addClass(cssName.replace("1", ""));

        });
        try
        {
            themeName = themeName.toLowerCase();
            var current = $(".mainTheme_" + themeName) || $(".mainTheme_" + themeName + "1");
            current.removeClass().addClass("mainTheme_" + themeName + "1");
        }
        catch (e) { }
        if (isCng)
        {
            RoadUI.Core.allFrames = [];
            RoadUI.Core.getAllFrames();
            for (var i = 0; i < RoadUI.Core.allFrames.length; i++)
            {
                $("#style_style", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/Content/Theme/" + themeName + "/Style/style.css");
                $("#style_ui", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/Content/Theme/" + themeName + "/Style/ui.css");
            }
            $.cookies.set("theme_platform", themeName, { expiresAt: new Date(2099, 1, 1) });
        }
    }

    function login()
    {
        openApp(rootdir + "/Login/Login?session=1", 2, "用户登录", "login", 400, 230);
    }

    //刷新一个页面
    function refreshPage(tabID)
    {
        if (!tabID)
        {
            tabID = 'tab_index';
        }
        mainTab.refresh(tabID);
        tabID = 'tab_edc4881b0ce1422e9e942808d47559e7';
        mainTab.refresh(tabID);
    }
</script>
